﻿using LeEdu.IDAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using LeEdu.Entity;
using LeEdu.DAL.DataAccess;
namespace LeEdu.DAL.DataAccess
{
    public class QuestionsDAL:BaseDAL,IQuestionsDAL
    {
		
		/// <summary>
		/// 添加试题
		/// </summary>
		/// <param name="quest"></param>
		/// <returns></returns>
        public bool Add(Entity.Questions quest)
        {
            //using (var conn=Connection)
            //{
            //    var result = conn.Execute("Insert into t_questions Values(@CourseId,@ClassHourId,@title,@qtype,@options,@answer,@analysis,@level,@score,@createtime,@edittime,@userId)", new { CourseId = quest.CourseId, ClassHourId = quest.ClassHourId, title = quest.Title, qtype = quest.Type, options = quest, answer = quest.Answer, analysis = quest.Analysis, level = quest.Difficulty, score = quest.Score, createtime = quest.CreateTime, edittime = quest.EditTime, userId = quest.UserId });
            //    return result > 0;
            //}
            return false;
        }

		/// <summary>
		/// 删除试题
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		public bool Del(int id) {
            //using (var conn=Connection)
            //{
            //    var result = conn.Execute("Delete t_questions where Id=@id", new { id = id });
            //    return result > 0;
            //}
            return false;
		}
		/// <summary>
		/// 编辑试题
		/// </summary>
		/// <param name="quest"></param>
		/// <returns></returns>
		public bool Edit(Entity.Questions quest) {
            //using (var conn=Connection)
            //{
            //    var result = conn.Execute("Update t_questions set CourseID=@CourseId,ClassHourID=@ClassHourId,Title=@title,QuestionType=@qtype,Options=@options,Answer=@answer,Analysis=@analysis,Difficulty=@level,Score=@score,CreateTime=@createtime,EditTime=@edittime,UserID=@userId", new { CourseId = quest.CourseId, ClassHourId = quest.ClassHourId, title = quest.Title, qtype = quest.Type, options = quest, answer = quest.Answer, analysis = quest.Analysis, level = quest.Difficulty, score = quest.Score, createtime = quest.CreateTime, edittime = quest.EditTime, userId = quest.UserId });
            //    return result > 0;
            //}
            return false;
		}
		/// <summary>
		/// 试题显示
		/// </summary>
		/// <returns></returns>
		public IEnumerable<Entity.Questions> GetAllQuestion(int id) 
        {
            //using (var conn=Connection)
            //{
            //    var result = conn.Query<Questions>("Select *,Uname from t_questions join UserInfoes on t_questions.UserID=UserInfoes.UserInfoId where CourseID=@id", new { id = id });
            //    return result;
            //}
            return null;
		}

		/// <summary>
		/// 获取试题数量
		/// </summary>
		/// <returns></returns>
		public int GetQuestionCount() {
            //using (var conn = Connection) {
            //    var result = conn.Query<Questions>("Select * from t_questions").Count();
            //    return result;
            //}
            return 0;
		}
	}
}
